/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.orm.*;

public class Profesional_SaludDAOImpl implements orm.orm.dao.Profesional_SaludDAO {
	public Profesional_Salud loadProfesional_SaludByORMID(Integer rutProf) throws PersistentException {
		try {
			PersistentSession session = orm.orm.TallerPersistentManager.instance().getSession();
			return loadProfesional_SaludByORMID(session, rutProf);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Profesional_Salud getProfesional_SaludByORMID(Integer rutProf) throws PersistentException {
		try {
			PersistentSession session = orm.orm.TallerPersistentManager.instance().getSession();
			return getProfesional_SaludByORMID(session, rutProf);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Profesional_Salud loadProfesional_SaludByORMID(Integer rutProf, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.orm.TallerPersistentManager.instance().getSession();
			return loadProfesional_SaludByORMID(session, rutProf, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Profesional_Salud getProfesional_SaludByORMID(Integer rutProf, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.orm.TallerPersistentManager.instance().getSession();
			return getProfesional_SaludByORMID(session, rutProf, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Profesional_Salud loadProfesional_SaludByORMID(PersistentSession session, Integer rutProf) throws PersistentException {
		try {
			return (Profesional_Salud) session.load(orm.orm.Profesional_Salud.class, rutProf);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Profesional_Salud getProfesional_SaludByORMID(PersistentSession session, Integer rutProf) throws PersistentException {
		try {
			return (Profesional_Salud) session.get(orm.orm.Profesional_Salud.class, rutProf);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Profesional_Salud loadProfesional_SaludByORMID(PersistentSession session, Integer rutProf, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Profesional_Salud) session.load(orm.orm.Profesional_Salud.class, rutProf, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Profesional_Salud getProfesional_SaludByORMID(PersistentSession session, Integer rutProf, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Profesional_Salud) session.get(orm.orm.Profesional_Salud.class, rutProf, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Profesional_Salud[] listProfesional_SaludByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.orm.TallerPersistentManager.instance().getSession();
			return listProfesional_SaludByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Profesional_Salud[] listProfesional_SaludByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.orm.TallerPersistentManager.instance().getSession();
			return listProfesional_SaludByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Profesional_Salud[] listProfesional_SaludByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.orm.Profesional_Salud as Profesional_Salud");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Profesional_Salud[]) list.toArray(new Profesional_Salud[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Profesional_Salud[] listProfesional_SaludByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.orm.Profesional_Salud as Profesional_Salud");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Profesional_Salud[]) list.toArray(new Profesional_Salud[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Profesional_Salud loadProfesional_SaludByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.orm.TallerPersistentManager.instance().getSession();
			return loadProfesional_SaludByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Profesional_Salud loadProfesional_SaludByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.orm.TallerPersistentManager.instance().getSession();
			return loadProfesional_SaludByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Profesional_Salud loadProfesional_SaludByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Profesional_Salud[] profesional_Saluds = listProfesional_SaludByQuery(session, condition, orderBy);
		if (profesional_Saluds != null && profesional_Saluds.length > 0)
			return profesional_Saluds[0];
		else
			return null;
	}
	
	public Profesional_Salud loadProfesional_SaludByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Profesional_Salud[] profesional_Saluds = listProfesional_SaludByQuery(session, condition, orderBy, lockMode);
		if (profesional_Saluds != null && profesional_Saluds.length > 0)
			return profesional_Saluds[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateProfesional_SaludByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.orm.TallerPersistentManager.instance().getSession();
			return iterateProfesional_SaludByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateProfesional_SaludByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.orm.TallerPersistentManager.instance().getSession();
			return iterateProfesional_SaludByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateProfesional_SaludByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.orm.Profesional_Salud as Profesional_Salud");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateProfesional_SaludByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.orm.Profesional_Salud as Profesional_Salud");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Profesional_Salud createProfesional_Salud() {
		return new orm.orm.Profesional_Salud();
	}
	
	public boolean save(orm.orm.Profesional_Salud profesional_Salud) throws PersistentException {
		try {
			orm.orm.TallerPersistentManager.instance().saveObject(profesional_Salud);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.orm.Profesional_Salud profesional_Salud) throws PersistentException {
		try {
			orm.orm.TallerPersistentManager.instance().deleteObject(profesional_Salud);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.orm.Profesional_Salud profesional_Salud)throws PersistentException {
		try {
			orm.orm.Encuesta[] lEncuestas = profesional_Salud.encuesta.toArray();
			for(int i = 0; i < lEncuestas.length; i++) {
				lEncuestas[i].setProfesional_SaludRutProf(null);
			}
			return delete(profesional_Salud);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.orm.Profesional_Salud profesional_Salud, org.orm.PersistentSession session)throws PersistentException {
		try {
			orm.orm.Encuesta[] lEncuestas = profesional_Salud.encuesta.toArray();
			for(int i = 0; i < lEncuestas.length; i++) {
				lEncuestas[i].setProfesional_SaludRutProf(null);
			}
			try {
				session.delete(profesional_Salud);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.orm.Profesional_Salud profesional_Salud) throws PersistentException {
		try {
			orm.orm.TallerPersistentManager.instance().getSession().refresh(profesional_Salud);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.orm.Profesional_Salud profesional_Salud) throws PersistentException {
		try {
			orm.orm.TallerPersistentManager.instance().getSession().evict(profesional_Salud);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Profesional_Salud loadProfesional_SaludByCriteria(Profesional_SaludCriteria profesional_SaludCriteria) {
		Profesional_Salud[] profesional_Saluds = listProfesional_SaludByCriteria(profesional_SaludCriteria);
		if(profesional_Saluds == null || profesional_Saluds.length == 0) {
			return null;
		}
		return profesional_Saluds[0];
	}
	
	public Profesional_Salud[] listProfesional_SaludByCriteria(Profesional_SaludCriteria profesional_SaludCriteria) {
		return profesional_SaludCriteria.listProfesional_Salud();
	}
}
